package com.trigram.dao.dynamic.mapper.dynamic;

import static com.trigram.dao.dynamic.mapper.dynamic.ModelEntityDynamicSqlSupport.approveprocessid;
import static com.trigram.dao.dynamic.mapper.dynamic.ModelEntityDynamicSqlSupport.filename;
import static com.trigram.dao.dynamic.mapper.dynamic.ModelEntityDynamicSqlSupport.industry1code;
import static com.trigram.dao.dynamic.mapper.dynamic.ModelEntityDynamicSqlSupport.industry1name;
import static com.trigram.dao.dynamic.mapper.dynamic.ModelEntityDynamicSqlSupport.industry2code;
import static com.trigram.dao.dynamic.mapper.dynamic.ModelEntityDynamicSqlSupport.industry2name;
import static com.trigram.dao.dynamic.mapper.dynamic.ModelEntityDynamicSqlSupport.investmentrate;
import static com.trigram.dao.dynamic.mapper.dynamic.ModelEntityDynamicSqlSupport.modelEntity;
import static com.trigram.dao.dynamic.mapper.dynamic.ModelEntityDynamicSqlSupport.modelid;
import static com.trigram.dao.dynamic.mapper.dynamic.ModelEntityDynamicSqlSupport.modelname;
import static com.trigram.dao.dynamic.mapper.dynamic.ModelEntityDynamicSqlSupport.newyear;
import static com.trigram.dao.dynamic.mapper.dynamic.ModelEntityDynamicSqlSupport.status;
import static com.trigram.dao.dynamic.mapper.dynamic.ModelEntityDynamicSqlSupport.stockcode;
import static com.trigram.dao.dynamic.mapper.dynamic.ModelEntityDynamicSqlSupport.stockname;
import static com.trigram.dao.dynamic.mapper.dynamic.ModelEntityDynamicSqlSupport.templateid;
import static com.trigram.dao.dynamic.mapper.dynamic.ModelEntityDynamicSqlSupport.unit;
import static com.trigram.dao.dynamic.mapper.dynamic.ModelEntityDynamicSqlSupport.updateremark;
import static com.trigram.dao.dynamic.mapper.dynamic.ModelEntityDynamicSqlSupport.updatetime;
import static com.trigram.dao.dynamic.mapper.dynamic.ModelEntityDynamicSqlSupport.user;
import static org.mybatis.dynamic.sql.SqlBuilder.isEqualTo;

import com.trigram.dao.dynamic.entity.po.ModelEntity;
import java.util.Collection;
import java.util.List;
import java.util.Optional;
import javax.annotation.Generated;
import org.apache.ibatis.annotations.ResultMap;
import org.apache.ibatis.annotations.SelectProvider;
import org.mybatis.dynamic.sql.BasicColumn;
import org.mybatis.dynamic.sql.delete.DeleteDSLCompleter;
import org.mybatis.dynamic.sql.select.CountDSLCompleter;
import org.mybatis.dynamic.sql.select.SelectDSLCompleter;
import org.mybatis.dynamic.sql.select.render.SelectStatementProvider;
import org.mybatis.dynamic.sql.update.UpdateDSL;
import org.mybatis.dynamic.sql.update.UpdateDSLCompleter;
import org.mybatis.dynamic.sql.update.UpdateModel;
import org.mybatis.dynamic.sql.util.SqlProviderAdapter;
import org.mybatis.dynamic.sql.util.mybatis3.CommonCountMapper;
import org.mybatis.dynamic.sql.util.mybatis3.CommonDeleteMapper;
import org.mybatis.dynamic.sql.util.mybatis3.CommonInsertMapper;
import org.mybatis.dynamic.sql.util.mybatis3.CommonUpdateMapper;
import org.mybatis.dynamic.sql.util.mybatis3.MyBatis3Utils;

public interface ModelDynamicSql
    extends CommonCountMapper, CommonDeleteMapper, CommonInsertMapper<ModelEntity>, CommonUpdateMapper {

  @Generated(comments = "Source Table: QYYJMX.T_IRM_EXCEL_MODEL", value = {})
  BasicColumn[] selectList = BasicColumn.columnList(
      modelid, modelname, user, stockcode, stockname, status, templateid, filename, industry1code, industry1name,
      industry2code, industry2name, newyear, updatetime, unit, investmentrate, updateremark, approveprocessid
  );

  @Generated(comments = "Source Table: QYYJMX.T_IRM_EXCEL_MODEL", value = {})
  static UpdateDSL<UpdateModel> updateAllColumns(ModelEntity row, UpdateDSL<UpdateModel> dsl) {

    return dsl.set(modelid).equalTo(row::getModelid)
        .set(modelname).equalTo(row::getModelname)
        .set(user).equalTo(row::getUser)
        .set(stockcode).equalTo(row::getStockcode)
        .set(stockname).equalTo(row::getStockname)
        .set(status).equalTo(row::getStatus)
        .set(templateid).equalTo(row::getTemplateid)
        .set(filename).equalTo(row::getFilename)
        .set(industry1code).equalTo(row::getIndustry1code)
        .set(industry1name).equalTo(row::getIndustry1name)
        .set(industry2code).equalTo(row::getIndustry2code)
        .set(industry2name).equalTo(row::getIndustry2name)
        .set(newyear).equalTo(row::getNewyear)
        .set(updatetime).equalTo(row::getUpdatetime)
        .set(unit).equalTo(row::getUnit)
        .set(investmentrate).equalTo(row::getInvestmentrate)
        .set(updateremark).equalTo(row::getUpdateremark)
        .set(approveprocessid).equalTo(row::getApproveprocessid);
  }

  @Generated(comments = "Source Table: QYYJMX.T_IRM_EXCEL_MODEL", value = {})
  static UpdateDSL<UpdateModel> updateSelectiveColumns(ModelEntity row, UpdateDSL<UpdateModel> dsl) {

    return dsl.set(modelid).equalToWhenPresent(row::getModelid)
        .set(modelname).equalToWhenPresent(row::getModelname)
        .set(user).equalToWhenPresent(row::getUser)
        .set(stockcode).equalToWhenPresent(row::getStockcode)
        .set(stockname).equalToWhenPresent(row::getStockname)
        .set(status).equalToWhenPresent(row::getStatus)
        .set(templateid).equalToWhenPresent(row::getTemplateid)
        .set(filename).equalToWhenPresent(row::getFilename)
        .set(industry1code).equalToWhenPresent(row::getIndustry1code)
        .set(industry1name).equalToWhenPresent(row::getIndustry1name)
        .set(industry2code).equalToWhenPresent(row::getIndustry2code)
        .set(industry2name).equalToWhenPresent(row::getIndustry2name)
        .set(newyear).equalToWhenPresent(row::getNewyear)
        .set(updatetime).equalToWhenPresent(row::getUpdatetime)
        .set(unit).equalToWhenPresent(row::getUnit)
        .set(investmentrate).equalToWhenPresent(row::getInvestmentrate)
        .set(updateremark).equalToWhenPresent(row::getUpdateremark)
        .set(approveprocessid).equalToWhenPresent(row::getApproveprocessid);
  }

  @Generated(comments = "Source Table: QYYJMX.T_IRM_EXCEL_MODEL", value = {})
  @SelectProvider(type = SqlProviderAdapter.class, method = "select")
  @ResultMap("BaseResultMap")
  List<ModelEntity> selectMany(SelectStatementProvider selectStatement);

  @Generated(comments = "Source Table: QYYJMX.T_IRM_EXCEL_MODEL", value = {})
  @SelectProvider(type = SqlProviderAdapter.class, method = "select")
  @ResultMap("BaseResultMap")
  Optional<ModelEntity> selectOne(SelectStatementProvider selectStatement);

  @Generated(comments = "Source Table: QYYJMX.T_IRM_EXCEL_MODEL", value = {})
  default long count(CountDSLCompleter completer) {

    return MyBatis3Utils.countFrom(this::count, modelEntity, completer);
  }

  @Generated(comments = "Source Table: QYYJMX.T_IRM_EXCEL_MODEL", value = {})
  default int delete(DeleteDSLCompleter completer) {

    return MyBatis3Utils.deleteFrom(this::delete, modelEntity, completer);
  }

  @Generated(comments = "Source Table: QYYJMX.T_IRM_EXCEL_MODEL", value = {})
  default int deleteByPrimaryKey(Short modelid_) {

    return delete(c ->
        c.where(modelid, isEqualTo(modelid_))
    );
  }

  @Generated(comments = "Source Table: QYYJMX.T_IRM_EXCEL_MODEL", value = {})
  default int insert(ModelEntity row) {

    return MyBatis3Utils.insert(this::insert, row, modelEntity, c ->
        c.map(modelid).toProperty("modelid")
            .map(modelname).toProperty("modelname")
            .map(user).toProperty("user")
            .map(stockcode).toProperty("stockcode")
            .map(stockname).toProperty("stockname")
            .map(status).toProperty("status")
            .map(templateid).toProperty("templateid")
            .map(filename).toProperty("filename")
            .map(industry1code).toProperty("industry1code")
            .map(industry1name).toProperty("industry1name")
            .map(industry2code).toProperty("industry2code")
            .map(industry2name).toProperty("industry2name")
            .map(newyear).toProperty("newyear")
            .map(updatetime).toProperty("updatetime")
            .map(unit).toProperty("unit")
            .map(investmentrate).toProperty("investmentrate")
            .map(updateremark).toProperty("updateremark")
            .map(approveprocessid).toProperty("approveprocessid")
    );
  }

  @Generated(comments = "Source Table: QYYJMX.T_IRM_EXCEL_MODEL", value = {})
  default int insertMultiple(Collection<ModelEntity> records) {

    return MyBatis3Utils.insertMultiple(this::insertMultiple, records, modelEntity, c ->
        c.map(modelid).toProperty("modelid")
            .map(modelname).toProperty("modelname")
            .map(user).toProperty("user")
            .map(stockcode).toProperty("stockcode")
            .map(stockname).toProperty("stockname")
            .map(status).toProperty("status")
            .map(templateid).toProperty("templateid")
            .map(filename).toProperty("filename")
            .map(industry1code).toProperty("industry1code")
            .map(industry1name).toProperty("industry1name")
            .map(industry2code).toProperty("industry2code")
            .map(industry2name).toProperty("industry2name")
            .map(newyear).toProperty("newyear")
            .map(updatetime).toProperty("updatetime")
            .map(unit).toProperty("unit")
            .map(investmentrate).toProperty("investmentrate")
            .map(updateremark).toProperty("updateremark")
            .map(approveprocessid).toProperty("approveprocessid")
    );
  }

  @Generated(comments = "Source Table: QYYJMX.T_IRM_EXCEL_MODEL", value = {})
  default int insertSelective(ModelEntity row) {

    return MyBatis3Utils.insert(this::insert, row, modelEntity, c ->
        c.map(modelid).toPropertyWhenPresent("modelid", row::getModelid)
            .map(modelname).toPropertyWhenPresent("modelname", row::getModelname)
            .map(user).toPropertyWhenPresent("user", row::getUser)
            .map(stockcode).toPropertyWhenPresent("stockcode", row::getStockcode)
            .map(stockname).toPropertyWhenPresent("stockname", row::getStockname)
            .map(status).toPropertyWhenPresent("status", row::getStatus)
            .map(templateid).toPropertyWhenPresent("templateid", row::getTemplateid)
            .map(filename).toPropertyWhenPresent("filename", row::getFilename)
            .map(industry1code).toPropertyWhenPresent("industry1code", row::getIndustry1code)
            .map(industry1name).toPropertyWhenPresent("industry1name", row::getIndustry1name)
            .map(industry2code).toPropertyWhenPresent("industry2code", row::getIndustry2code)
            .map(industry2name).toPropertyWhenPresent("industry2name", row::getIndustry2name)
            .map(newyear).toPropertyWhenPresent("newyear", row::getNewyear)
            .map(updatetime).toPropertyWhenPresent("updatetime", row::getUpdatetime)
            .map(unit).toPropertyWhenPresent("unit", row::getUnit)
            .map(investmentrate).toPropertyWhenPresent("investmentrate", row::getInvestmentrate)
            .map(updateremark).toPropertyWhenPresent("updateremark", row::getUpdateremark)
            .map(approveprocessid).toPropertyWhenPresent("approveprocessid", row::getApproveprocessid)
    );
  }

  @Generated(comments = "Source Table: QYYJMX.T_IRM_EXCEL_MODEL", value = {})
  default Optional<ModelEntity> selectOne(SelectDSLCompleter completer) {

    return MyBatis3Utils.selectOne(this::selectOne, selectList, modelEntity, completer);
  }

  @Generated(comments = "Source Table: QYYJMX.T_IRM_EXCEL_MODEL", value = {})
  default List<ModelEntity> select(SelectDSLCompleter completer) {

    return MyBatis3Utils.selectList(this::selectMany, selectList, modelEntity, completer);
  }

  @Generated(comments = "Source Table: QYYJMX.T_IRM_EXCEL_MODEL", value = {})
  default List<ModelEntity> selectDistinct(SelectDSLCompleter completer) {

    return MyBatis3Utils.selectDistinct(this::selectMany, selectList, modelEntity, completer);
  }

  @Generated(comments = "Source Table: QYYJMX.T_IRM_EXCEL_MODEL", value = {})
  default Optional<ModelEntity> selectByPrimaryKey(Short modelid_) {

    return selectOne(c ->
        c.where(modelid, isEqualTo(modelid_))
    );
  }

  @Generated(comments = "Source Table: QYYJMX.T_IRM_EXCEL_MODEL", value = {})
  default int update(UpdateDSLCompleter completer) {

    return MyBatis3Utils.update(this::update, modelEntity, completer);
  }

  @Generated(comments = "Source Table: QYYJMX.T_IRM_EXCEL_MODEL", value = {})
  default int updateByPrimaryKey(ModelEntity row) {

    return update(c ->
        c.set(modelname).equalTo(row::getModelname)
            .set(user).equalTo(row::getUser)
            .set(stockcode).equalTo(row::getStockcode)
            .set(stockname).equalTo(row::getStockname)
            .set(status).equalTo(row::getStatus)
            .set(templateid).equalTo(row::getTemplateid)
            .set(filename).equalTo(row::getFilename)
            .set(industry1code).equalTo(row::getIndustry1code)
            .set(industry1name).equalTo(row::getIndustry1name)
            .set(industry2code).equalTo(row::getIndustry2code)
            .set(industry2name).equalTo(row::getIndustry2name)
            .set(newyear).equalTo(row::getNewyear)
            .set(updatetime).equalTo(row::getUpdatetime)
            .set(unit).equalTo(row::getUnit)
            .set(investmentrate).equalTo(row::getInvestmentrate)
            .set(updateremark).equalTo(row::getUpdateremark)
            .set(approveprocessid).equalTo(row::getApproveprocessid)
            .where(modelid, isEqualTo(row::getModelid))
    );
  }

  @Generated(comments = "Source Table: QYYJMX.T_IRM_EXCEL_MODEL", value = {})
  default int updateByPrimaryKeySelective(ModelEntity row) {

    return update(c ->
        c.set(modelname).equalToWhenPresent(row::getModelname)
            .set(user).equalToWhenPresent(row::getUser)
            .set(stockcode).equalToWhenPresent(row::getStockcode)
            .set(stockname).equalToWhenPresent(row::getStockname)
            .set(status).equalToWhenPresent(row::getStatus)
            .set(templateid).equalToWhenPresent(row::getTemplateid)
            .set(filename).equalToWhenPresent(row::getFilename)
            .set(industry1code).equalToWhenPresent(row::getIndustry1code)
            .set(industry1name).equalToWhenPresent(row::getIndustry1name)
            .set(industry2code).equalToWhenPresent(row::getIndustry2code)
            .set(industry2name).equalToWhenPresent(row::getIndustry2name)
            .set(newyear).equalToWhenPresent(row::getNewyear)
            .set(updatetime).equalToWhenPresent(row::getUpdatetime)
            .set(unit).equalToWhenPresent(row::getUnit)
            .set(investmentrate).equalToWhenPresent(row::getInvestmentrate)
            .set(updateremark).equalToWhenPresent(row::getUpdateremark)
            .set(approveprocessid).equalToWhenPresent(row::getApproveprocessid)
            .where(modelid, isEqualTo(row::getModelid))
    );
  }

}